#include "PlayerEvent.h"
#include "SubsystemChatLimit.h"
#include "Player/PlayerData.h"

#include "Network/PackageManager.h"
#include "Network/Packages/MessagePackage.h"
#include "GameSingleton.h"

using namespace PocketSurvival;

namespace ChatLimit
{
    bool PlayerEvent::message(std::shared_ptr<PlayerData> playerData, std::string &message, std::vector<uint8_t> &toClients)
    {
        ChatLimitType type =  m_subsystemChatLimit->addMessageCount(playerData->username);
        if (message.find("p>") != std::string::npos)
        {
            playerData->client->disconnect("服务器禁止发送敏感消息，违者踢出服务器");
            return false;
        }
        if(type == ChatLimitType::Normal)
        {
            return true;
        }
        if(type == ChatLimitType::Limit)
        {
            std::shared_ptr<MessagePackage> package = std::make_shared<MessagePackage>("你已经被限制发言了,请等一会再发送消息");
            package->sendType = PackageSendType::TARGET;
            package->client = playerData->client;
            GameSingleton::packageManager->addSendPackageToQueue(package);
        }
        else
        {
            playerData->client->disconnect("请不要刷屏");
        }
        return false;
    }
}
